package com.dycx.api.controller.app.user;

import com.dycx.common.RestResponse;
import com.dycx.common.annotation.Authorization;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.context.UserInfoContext;
import com.dycx.common.enums.BizTypeEnum;
import com.dycx.user.dto.SellerDTO;
import com.dycx.user.service.SellerService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;


@RestController
@RequestMapping(value = "/app/user/seller")
public class SellerApiController {

    @Resource
    private SellerService sellerService;

    /**
     * 添加
     *
     * @param sellerDto
     * @return
     */
    @Authorization
    @WriterLog(bizType = BizTypeEnum.USER_SELLER, bizValue = "{#sellerDto.id}")
    @PostMapping("create")
    public RestResponse<Boolean> create(@RequestBody @Valid SellerDTO sellerDto) {
        sellerDto.setUid(UserInfoContext.get().getUserId());
        return sellerService.addSeller(sellerDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改
     *
     * @param sellerDto
     * @return
     */
    @Authorization
    @WriterLog(bizType = BizTypeEnum.USER_SELLER, bizValue = "{#sellerDto.id}")
    @PostMapping("edit")
    public RestResponse<Boolean> edit(@RequestBody @Valid SellerDTO sellerDto) {
        sellerDto.setUid(UserInfoContext.get().getUserId());
        return sellerService.edit(sellerDto) ? RestResponse.success() : RestResponse.fail();
    }



}
